package ch.myDungeons.game;

import java.io.Serializable;

import ch.myDungeons.characters.*;

/**
 * A Tile of the map. Equivalent to 2m*2m
 * @author Grii
 *
 */

public class Tile implements Serializable{
	private static final long serialVersionUID = -8575122943988332004L;

	/** Dropped items on this tile */
	public Inventory inventory = new Inventory();
	
	/** whether the tile is an obstacle or accessible */
	public boolean accessible = false;
		
	/** Where this tile is on the map */
	public int posX, posY;
	
	/** Points to the character on this tile */
	public Person personOnTheTile;
	
	/** True if stairs up */
	public boolean isStairsUp = false;
	
	/** True is stairs down */
	public boolean isStairsDown = false;
	
	public Tile (boolean accessible, int posX, int posY) {
		this.accessible = accessible;
		this.posX = posX;
		this.posY = posY;
	}

	/** returns accessible, stairsUp, stairsDown, items, personOnTheTile. split at TILEINFO */
	public String getSave() {
		String result = accessible + "<TILEINFO>" + isStairsUp + "<TILEINFO>" + isStairsDown + "<TILEINFO>";
		for (int i = 0; i < inventory.size(); i++) {
			result += "\n<ITEM>" + inventory.get(i).getSave();
		}
		result += "<TILEINFO>";
		if (personOnTheTile == null) {
			result += "null";
		} else {
			result += "\n" + personOnTheTile.getSave();
		}
		return result;
	}
}
